<template>
  <el-select-v2
    v-model="value"
    :options="brandOption"
    v-bind="$attrs"
    clearable
    filterable
    @change="change"
    :placeholder="props.placeholder"
    :multiple="props.multiple"
  >
  </el-select-v2>
</template>
<script setup>
import useCommonStore from "@/store/modules/common";
const commonStore = useCommonStore();
const brandOption = computed(() => {
  if (!commonStore.brandOption) {
    commonStore.getBrandList();
  }
  return commonStore.brandOption || [];
});
const props = defineProps({
  modelValue: [String, Number, Array],
  placeholder: {
    type: String,
    default: "请选择",
  },
  multiple: {
    type: Boolean,
    default: false,
  },
});

const value = computed({
  get: () => {
    return props.modelValue || null;
  },
  set: (val) => {
    emit("update:modelValue", val);
  },
});

const emit = defineEmits(["update:modelValue", "change", "changeName"]);
const change = (val) => {
  const item = brandOption.value.find((i) => i.value == val);
  emit("change", item?.value);
  emit("changeName", item?.label);
};
</script>
